﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.IO;

namespace CrazyClient
{
    [XmlRoot("AssetRoot")]
    public class Asset : IXmlSerializable
    {
        public Asset()
        {
        }
        public Asset(string asset)
        {
            _asset = asset;
        }
        string _asset;
        public string AssetXml
        {
            get
            {
                return _asset;
            }
        }
        public System.Xml.Schema.XmlSchema GetSchema()
        {
            throw new NotImplementedException();
        }

        public void ReadXml(System.Xml.XmlReader reader)
        {
            reader.ReadStartElement("AssetRoot");
            this._asset = (string)reader.ReadElementContentAsObject("_asset", "");
            reader.ReadEndElement();
        }
        public static Asset Load(string xmlFile)
        {
            FileStream stream = new FileStream(xmlFile, FileMode.OpenOrCreate);
            XmlSerializer x = new XmlSerializer(typeof(Asset));

            Asset si = (Asset)x.Deserialize(stream);
            stream.Close();
            return si;
        }
        public void WriteXml(System.Xml.XmlWriter writer)
        {

            writer.WriteStartElement("_asset");
            writer.WriteValue(this._asset.ToString());
            writer.WriteEndElement();

        }
    }
}
